package com.potenza.training.resume.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.potenza.training.resume.dao.DocumentDao;
import com.potenza.training.resume.entity.DocumentEntity;
import com.potenza.training.resume.service.DocumentService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("documentService")
public class DocumentServiceImpl extends ServiceImpl<DocumentDao, DocumentEntity> implements DocumentService {

    @Autowired
    DocumentDao documentDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<DocumentEntity> page = this.page(
                new Query<DocumentEntity>().getPage(params),
                new QueryWrapper<DocumentEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void deleteById(String document, Integer resumeId) {
        QueryWrapper<DocumentEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(DocumentEntity::getDocument,document);
        queryWrapper.lambda().eq(DocumentEntity::getResumeId,resumeId);
        DocumentEntity documentEntity = documentDao.selectOne(queryWrapper);
        documentDao.deleteById(documentEntity);
    }

    @Override
    public List<DocumentEntity> findByresumeId(Integer resumeId) {
        QueryWrapper<DocumentEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(DocumentEntity::getResumeId,resumeId);
        return documentDao.selectList(queryWrapper);
    }

}